package com.chuanjiabao.wisdom.util.dialog;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.chuanjiabao.wisdom.R;
import com.chuanjiabao.wisdom.databinding.DialogShareBinding;
import com.chuanjiabao.wisdom.listener.OnShareStypeClickListener;

public class ShareDialog extends BaseDialog implements View.OnClickListener {

    private String shareType;
    private DialogShareBinding binding;
    private OnShareStypeClickListener listener;

    public void setOnShareStypeClickListener(OnShareStypeClickListener listener) {
        this.listener = listener;
    }

    public ShareDialog(Context context, String shareType) {
        super(context);
        this.shareType = shareType;
        binding = DataBindingUtil.inflate(
                LayoutInflater.from(context),
                R.layout.dialog_share,
                null,
                false
        );
        binding.setDialog(this);
        setContentView(binding.getRoot());
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(layoutParams);
        //弹窗弹出在底部，默认中部
        getWindow().setGravity(Gravity.BOTTOM);
        initView();
    }

    private void initView() {
        switch (shareType) {
            case "image":
                binding.llModuleQQ.setVisibility(View.VISIBLE);
                binding.llModuleWx.setVisibility(View.VISIBLE);
                binding.llModuleSave.setVisibility(View.VISIBLE);
                break;
            case "video":
                binding.llModuleQQ.setVisibility(View.GONE);
                binding.llModuleWx.setVisibility(View.GONE);
                binding.llModuleSave.setVisibility(View.VISIBLE);
                break;
            case "invite":
                binding.llModuleQQ.setVisibility(View.VISIBLE);
                binding.llModuleWx.setVisibility(View.VISIBLE);
                binding.llModuleSave.setVisibility(View.GONE);
                break;
        }

        binding.dialogNo.setOnClickListener(this);
        binding.llModuleQQ.setOnClickListener(this);
        binding.llModuleWx.setOnClickListener(this);
        binding.llModuleSave.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llModuleQQ:
                if (listener != null) {
                    listener.setOnShareStyleClickListener("QQ");
                }
                dismiss();
                break;
            case R.id.llModuleWx:
                if (listener != null) {
                    listener.setOnShareStyleClickListener("Wx");
                }
                dismiss();
                break;
            case R.id.llModuleSave:
                if (listener != null) {
                    listener.setOnShareStyleClickListener("save");
                }
                dismiss();
                break;
            case R.id.dialogNo:
                if (listener != null) {
                    listener.setOnShareStyleClickListener("cancel");
                }
                dismiss();
                break;
        }
    }

}


